$(document).ready(function () {

    //FCE的核心服务IP地址.
    var portAddress = window.sessionStorage.getItem("portAddress");

    //去重的方法
    function removeDuplicate(arr) {
        const newArr = []
        arr.forEach(item => {
            if (!newArr.includes(item)) {
                newArr.push(item)
            }
        })
        return newArr
    }


    //使用AJAX获取询价数据使用折线图进行展示.
    var myChartOne = echarts.init(document.getElementById('data_one'));
    var option_one;

    $.ajax({
        url : portAddress + "/provider/getEcharts",
        type : "get",
        dataType : "json",
        success : function(res) {
            if (res.state === "000000") {
                const values = Array.from(res.data.values()).map(value => value);

                const counts = Array.from(values.values()).map(value => value.count).reverse();

                const dates = Array.from(values.values()).map(value => value.tradeDate).reverse();

                option_one = {
                    title: {
                        text: 'RFQ',
                    },
                    tooltip: {
                        trigger: 'axis'
                    },
                    xAxis: {
                        type: 'category',
                        data: dates,
                        boundaryGap: false
                    },
                    yAxis: {
                        type: 'value',
                        minInterval: 1
                    },
                    series: [
                        {
                            data: counts,
                            type: 'line',
                            smooth: true
                        }
                    ]
                };
            }
            option_one && myChartOne.setOption(option_one);
        }
    })


    /*-------------------------------------------------------------*/
    //使用AJAX获取账务数据使用折线图进行展示.
    var  myChartTwo = echarts.init(document.getElementById('data_two'));
    var option_two;

    $.ajax({
        url : portAddress + "/accountingEntry/getAccountingEcharts",
        type : "get",
        dataType : "json",
        success : function(res) {
            if (res.state === "000000") {
                const values = Array.from(res.data.values()).map(value => value);
                const counts = Array.from(values.values()).map(value => value.count).reverse();

                const dates = Array.from(values.values()).map(value => value.acDate).reverse();

                option_two = {
                    title: {
                        text: 'Accounting',
                    },
                    tooltip: {
                        trigger: 'axis'
                    },
                    xAxis: {
                        type: 'category',
                        data: dates,
                        boundaryGap: false
                    },
                    yAxis: {
                        type: 'value',
                        minInterval: 1
                    },
                   series: [
                        {
                            data: counts,
                            type: 'line',
                            smooth: true
                        }
                    ]
                };
            }
            option_two && myChartTwo.setOption(option_two);
        }
    })


    /*-------------------------------------------------------------*/
    //使用AJAX获取Transaction数据使用柱状图进行展示.
    var  myChartThree = echarts.init(document.getElementById('data_three'));
    var option_three;
    $.ajax({
        url : portAddress + "/transaction/getEcharts",
        type : "get",
        dataType : "json",
        success : function(res) {
            if (res.state === "000000") {
                const values = Array.from(res.data.values()).map(value => value);

                const counts = Array.from(values.values()).map(value => value.count).reverse();

                const dates = Array.from(values.values()).map(value => value.tradeDate).reverse();

                option_three = {
                    title: {
                        text: "Transaction",
                        left: 'left',
                    },
                    xAxis: {
                        type: 'category',
                        data: dates,
                        name: '时间'
                    },
                    yAxis: {
                        type: 'value',
                        name: '总数',
                        minInterval: 1
                    },
                    series: [
                        {
                            data: counts,
                            type: 'bar',
                            showBackground: true,
                            backgroundStyle: {
                                color: 'rgba(180, 180, 180, 0.2)'
                            }
                        }
                    ]
                };
            }
            option_three && myChartThree.setOption(option_three);
        }
    })



    /*-------------------------------------------------------------*/
    //使用AJAX获取Position数据使用饼状图进行展示.
    var  myChartFour = echarts.init(document.getElementById('data_four'));
    var option_four;
    $.ajax({
        url : portAddress + "/position/positionEchartsList",
        type : "get",
        dataType : "json",
        success : function(res) {
            if (res.state === "000000") {
                const datas = Array.from(res.data.values()).map(value => value);
                option_four = {
                    title: {
                        text: 'Position',
                        left: 'left'
                    },
                    tooltip: {
                        trigger: 'item'
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'right', // 设置legend位于右侧
                        top: 'center' // 设置legend位于中心
                    },
                    series: [
                        {
                            name: '拆盘状态DON/NOR数量',
                            type: 'pie',
                            radius: '50%',
                            data: datas,
                            emphasis: {
                                itemStyle: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                };

            }
            option_four && myChartFour.setOption(option_four);
        }
    })

})
